﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tong;
public partial class Use_User_Edit : System.Web.UI.Page
{
    /// <summary>
    /// 用户的id 
    /// </summary>
    string id;
    /// <summary>
    /// 
    /// 用户名
    /// </summary>
    string use;
    /// <summary>
    /// 数据操作通用类 实例 TextData
    /// </summary> 
    public TongUse TextData = new TongUse();

    /// <summary>
    /// 系统安装绝对路径
    /// </summary>
    public string Abs_Path = TongUse.SysPath;
   
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            id = Request.QueryString["id"].ToString();//得到修改用户的id
            use = Request.QueryString["use"].ToString();//得到修改用户的id
            Page.Title = "修改" + use + "的信息页面";//页面标题
            EditFlg.NavigateUrl = "~/aspnet/admin/use/Use_Edit_flg.aspx?id="+id+"&use="+use;//编辑这个用户的用户菜单显示权限
            Tabtt.Text = use;
            

        }
        catch(EvaluateException ex)
        {
            TextData.Err(ex.Message);
        }

        DataTable MyDt = TextData.SqlataSet("select * from [Use] where Use_id = " + id).Tables[0];//得到这个用户的所有记录

        ChangePwd();//更新密码

        useX.Text = MyDt.Rows[0]["uid"].ToString();//用户名
        Use_flg.Text = MyDt.Rows[0]["flg"].ToString();//用户权限
        Use_Name.Text = MyDt.Rows[0]["UseName"].ToString();//用户姓名
        MyDt.Clear();//清空变量
       
    }

    /// <summary>
    /// 更新密码
    /// </summary>
    protected void ChangePwd()
    {
        if (pwd.Text.Trim() != "" && id != null)
        {

            TextData.SqlDataSave("Update [Use] Set pwd = '" + TextData.SHA1Sign(pwd.Text.Trim()) + "' where Use_id  = " + id);
            tt.Text = "用户" + useX.Text + "的密码数据成功更新";
            pwd.Text = "";
        }
        else
        {
            //看看有没有修改用户姓名
            if (Use_Name.Text.Trim() != "" && pwd.Text.Trim() == "")
            {

                TextData.SqlDataSave("Update [Use] Set UseName ='" + Use_Name.Text.Trim() + "' where Use_id  = " + id);
                tt.Text = "用户" + useX.Text + "的用户姓名数据成功更新";
            }
            else
            {
                //同时修改用户名和密码
                if (Use_Name.Text.Trim() != "" && pwd.Text.Trim() != "")
                {
                    TextData.SqlDataSave("Update [Use] Set UseName ='" + Use_Name.Text.Trim() + "', pwd = '" + TextData.SHA1Sign(pwd.Text.Trim()) + "'  where Use_id  = " + id);
                   
                    tt.Text = "用户" + useX.Text + "的用户姓名与密码成功更新";
                }
                
            }
           
            
        }
    }
}
